package com.bjtu.laorenyouhao.laoren.service.impl;

import com.bjtu.laorenyouhao.laoren.feign.LaorenFeignService;
import com.bjtu.laorenyouhao.laoren.utils.RenyuanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjtu.common.utils.PageUtils;
import com.bjtu.common.utils.Query;

import com.bjtu.laorenyouhao.laoren.dao.HealthDao;
import com.bjtu.laorenyouhao.laoren.entity.HealthEntity;
import com.bjtu.laorenyouhao.laoren.service.HealthService;
import org.springframework.util.StringUtils;


@Service("healthService")
public class HealthServiceImpl extends ServiceImpl<HealthDao, HealthEntity> implements HealthService {

    @Autowired
    private LaorenFeignService laorenFeignService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String key = (String) params.get("key");
        QueryWrapper<HealthEntity> queryWrapper = new QueryWrapper<HealthEntity>();
        if (StringUtils.hasLength(key)) {
            Integer emotion_type = 8;
            switch (key) {
                case "愤怒":
                    emotion_type = 1;
                    break;
                case "厌恶":
                    emotion_type = 2;
                    break;
                case "恐惧":
                    emotion_type = 3;
                    break;
                case "高兴":
                    emotion_type = 4;
                    break;
                case "正常":
                    emotion_type = 5;
                    break;
                case "悲伤":
                    emotion_type = 6;
                    break;
                case "惊讶":
                    emotion_type = 7;
                    break;
            }
            queryWrapper.eq("id", key)
                    .or().like("emotion_type", emotion_type)
                    .or().eq("laoren_id", RenyuanUtils.getLaorenId(key,laorenFeignService));
        }

        IPage<HealthEntity> page = this.page(
                new Query<HealthEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}